package cn.edu.scau.cmi.huangzhiyuan.adapter;

import cn.edu.scau.cmi.huangzhiyuan.abstractFactory.factory.AbstractFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Client extends Application {
	private Label display = new Label("none");
	Target classTarget = new AdapterOfClass();
	Target objectTarget = new AdapterOfObject(); 

	@Override
	public void start(Stage primaryStage) throws Exception {

		// 构造选项
		ChoiceBox<String> cb = new ChoiceBox<String>();
		cb.setItems(FXCollections.observableArrayList("类适配器", "对象适配器"));

		// 设置box、选项、按钮
		VBox box = new VBox();
		box.setMaxWidth(300);
		box.setMaxHeight(100);
		box.getChildren().add(cb);
		box.getChildren().add(display);
		cb.setOnAction(event -> {
			if(cb.getSelectionModel().getSelectedIndex() == 0) {
				display.setText(classTarget.doTarget());
			} else {
				display.setText(objectTarget.doTarget());
			}
		});

		StackPane pane = new StackPane();
		pane.getChildren().add(box);

		// 设置面板
		Scene scene = new Scene(pane, 400, 200);

		// 放置面板
		primaryStage.setScene(scene);

		// 设置窗口标题
		primaryStage.setTitle("实验四：适配器模式");

		// 展示
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}

}